package com.hsq.androidproject.ui;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.lenovo.androidproject3.R;
import com.hsq.androidproject.ui.Users.ShowUsers;
import com.hsq.androidproject.utils.FragmentUtil;

public class MainActivity extends FragmentActivity implements RadioGroup.OnCheckedChangeListener {
    private RadioGroup mGroup;
    private FragmentUtil intance;
    RadioButton rb_recommend, rb_find, rb_watching;
    private Drawable drawablerb_recommend;
    private Drawable drawablerb_find;
    private Drawable drawablerb_watching;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        intance = FragmentUtil.getIntance(this, R.id.fl_content);
        intance.showFragment(0);


    }

    private void initView() {
        mGroup = (RadioGroup) findViewById(R.id.rg_tab);
        mGroup.setOnCheckedChangeListener(this);
        rb_recommend = (RadioButton) findViewById(R.id.rb_recommend);
        rb_find = (RadioButton) findViewById(R.id.rb_find);
        rb_watching = (RadioButton) findViewById(R.id.rb_watching);

        drawablerb_recommend = getResources().getDrawable(R.drawable.icon_recommend);
        drawablerb_recommend.setBounds(0, 0, 145, 65);//第一0是距左右边距离，第二0是距上下边距离，第三宽度,第四高度
        rb_recommend.setCompoundDrawables(null, drawablerb_recommend, null, null);//只放上面/////

        drawablerb_find = getResources().getDrawable(R.drawable.icon_find);
        drawablerb_find.setBounds(0, 0, 145, 65);//第一0是距左右边距离，第二0是距上下边距离，第三宽度,第四高度
        rb_find.setCompoundDrawables(null, drawablerb_find, null, null);//只放上面

        drawablerb_watching = getResources().getDrawable(R.drawable.icon_watching);
        drawablerb_watching.setBounds(0, 0, 145, 65);//第一0是距左右边距离，第二0是距上下边距离，第三宽度,第四高度
        rb_watching.setCompoundDrawables(null, drawablerb_watching, null, null);//只放上面
    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rb_recommend:
                intance.showFragment(0);
                break;
            case R.id.rb_find:
                intance.showFragment(1);
                break;
            case R.id.rb_watching:
//                intance.showFragment(2);
                Intent intent=new Intent(this,ShowUsers.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //解决v4包bug fragment报错  activity has been destroyed 的方案
        android.os.Process.killProcess(android.os.Process.myPid());//获取PID
        System.exit(0);

    }
}
